package com.github.dreamyoung.mprelation.demo.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.github.dreamyoung.mprelation.*;
import com.github.dreamyoung.mprelation.demo.mapper.OptionalMapper;
import lombok.Data;

import java.util.List;

/**
 * @author lxl
 * @date 2022/4/10
 */
@Data
public class Student {
    /**
     * 学生Id
     */
    @TableId(value = "stu_id")
    private Integer id;
    /**
     * 学生姓名
     */
    private String stuName;
    /**
     * 学生住址
     */
    private String stuAddress;
    /**
     * 年级id
     */
    private Integer gradeId;
    /**
     * 一对一关系 （一个学生只有一个年级）
     */
    @TableField(exist = false)
    @OneToOne
    @JoinColumn(name = "grade_id", referencedColumnName = "grade_id")
    @Lazy(value = false)
    private Grade grade;
    /**
     * 多对多
     */
    @TableField(exist = false)
    @ManyToMany
    @JoinTable(targetMapper = OptionalMapper.class)
    //stu表id对应opt表关联id
    @JoinColumn(name = "stu_id", referencedColumnName = "stu_id")
    // sub表对应opt 关联id
    @InverseJoinColumn(name = "sub_id", referencedColumnName = "sub_id")
    private List<Subject>  subjectList;
}
